﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2
{
    internal class ATM
    {
        public event EventHandler<BigMoneyArgs> BigMoneyFetched;

        public decimal Withdraw(Account account, decimal amount)
        {
            if (amount > 10000)
            {
                OnBigMoneyFetched(new BigMoneyArgs(account, amount));
            }

            return account.Withdraw(amount);
        }

        public decimal Deposit(Account account, decimal amount)
        {
            // 模拟坏钞，这里认为只有存款会出现坏钞
            if (new Random().Next(100) < 30) // 30% 概率抛出异常
            {
                throw new BadCashException("出现坏钞，请取出！");
            }
            account.Deposit(amount);
            return account.Balance;
        }

        protected virtual void OnBigMoneyFetched(BigMoneyArgs e)
        {
            BigMoneyFetched?.Invoke(this, e);
        }
    }
}
